package com.sky.mapper;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.entity.OrdersStatistics;
import com.sky.entity.Sales;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    //新增订单
    void add(Orders orders);

    //分页条件查询用户历史订单
    List<OrderVO> list(Orders orders);

    /**
     * 根据订单号查询订单
     *
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     *
     * @param orders
     */
    void update(Orders orders);

    //订单搜索
    List<OrderVO> selAllOrders(OrdersPageQueryDTO ordersPageQueryDTO);

    //某段时间内各个状态的订单数量统计
    Integer selOrderStatistics(Map map);

    //定时任务查询数据库
    @Select("select * from orders where status = #{status} and order_time < #{orderTime};")
    List<Orders> toTaskSelOrder(Orders orders);

    //营业额统计接口
    Double turnoverStatistics(HashMap<Object, Object> map);

    //查询销量排名
    List<Sales> selSalesTop(HashMap<Object, Object> map);

    //统计每日订单数和有效订单数
    @Select("select count(*) orderQuantity, sum(status=5) succeedOrderQuantity from orders where order_time between #{begin} and #{end};")
    OrdersStatistics ordersStatistics(HashMap<Object, Object> map);

}
